package cn.wfu.rlrjds.web.repaire.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.wfu.rlrjds.app.bean.RepaireBean;
import cn.wfu.rlrjds.app.bean.RepaireSearch;
import cn.wfu.rlrjds.app.bean.UserSearch;
import cn.wfu.rlrjds.app.repaire.service.IRepaireService;
import cn.wfu.rlrjds.app.repairman.domain.Repaireman;
import cn.wfu.rlrjds.app.repairman.service.IRepairmanService;
import cn.wfu.rlrjds.app.user.domain.User;
import cn.wfu.rlrjds.app.user.service.IUserService;

@Controller(value = "webRepaireController")
@RequestMapping(value = "/web/repaire")
public class RepaireController {

	@Resource
	private IRepaireService repaireService;

	@Autowired
	private IRepairmanService repairmanService;

	/**
	 * 跳转到显示页面
	 */
	@RequestMapping(value = "/list")
	public String list(HttpServletRequest request, RepaireSearch repaireSearch) {
		// 查询维修员信息
		List<Repaireman> repairemans = this.repairmanService.list();
		List<RepaireBean> repaireBeans = this.repaireService
				.list(repaireSearch);
		request.setAttribute("repairemans", repairemans);
		request.setAttribute("repaireBeans", repaireBeans);
		return "repaire/list";
	}

	/**
	 * 加载订单的详细信息
	 */
	@RequestMapping(value = "/load")
	public String load(HttpServletRequest request, RepaireSearch repaireSearch) {
		// 查询维修员信息
		RepaireBean repaireBean = this.repaireService.findOne(repaireSearch);
		request.setAttribute("repaireBean", repaireBean);
		return "repaire/repaire";
	}

	/**
	 * 删除维修记录
	 */
	@RequestMapping(value = "/delete")
	public String delete(HttpServletRequest request, RepaireSearch repaireSearch) {
		String[] ids = request.getParameterValues("ids");
		this.repaireService.deleteRepaireByIds(ids);
		return "redirect:/web/" + this.list(request, new RepaireSearch());
	}

}
